package com.example.todolist.controller;

import com.example.todolist.entity.User;
import com.example.todolist.service.UserService;
import com.example.todolist.tools.ResponseBody;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

//对于user的操作，增删改查
@RestController
@RequestMapping("/user")
public class UserController {
    @Autowired
    private UserService userService;
    @PostMapping("/register")
    public ResponseBody<Integer> register(@RequestBody User user)
    {
        return userService.register(user);
    }
    @PostMapping("/register/confirm")
    public ResponseBody<Integer> registerConfirm(@RequestBody User user,@RequestParam Integer number) {
        return userService.registerConfirm(user,number);
    }
    @GetMapping("/login")
    private ResponseBody<Integer> login(@RequestParam String name, @RequestParam String password) {
        return userService.login(name,password);
    }
    @PostMapping("/updateEmail")     //更新用户邮箱
    public ResponseBody<Integer> updateEmail(@RequestParam Integer userId,@RequestParam String email) {
        return userService.updateEmail(userId,email);
    }
    @PostMapping("/updatePassword")    //更新用户密码
    public ResponseBody<Integer> updatePassword(@RequestParam Integer userId,@RequestParam String password) {
        return userService.updatePassword(userId,password);
    }
    @GetMapping("/findByUserId")
    public ResponseBody<User> findByUserId(@RequestParam Integer userId)
    {
        return userService.findByUserId(userId);
    }
}
